############################
# Replication file: "Insiders, outsiders, skills and preferences for social protection: evidence from a survey experiment in Argentina"
# Irene Men�ndez Gonz�lez, January 2021
############################

# Figure 3: plotting differential effect of treatment for groups of respondents based on other politically/economically salient characteristics
library(readxl) 

# All tests include controls included in baseline models (age, gender, province). Also include education and insider dummies when not testing effect of low-skill insider/low-skill worker.

res <- read_excel("Fig3Estimates.xlsx", sheet="Main", col_names = TRUE)

coef.risk <- res$coef.risk
se.risk <- res$se.risk

coef.pov <- res$coef.pov
se.pov <- res$se.pov


#Estimation results from Stata
#coef.risk <- c(0.104, 0.123, -0.0061, 0.3097, 0.136, 0.163, 0.033, 0.070, -0.143, 0.164, 0.427) # Difference across group from group*risk frame interaction 
#se.risk <- c(0.135, 0.182, 0.1357, 0.1848, 0.139, 0.131, 0.102, 0.134, 0.129, 0.172, 0.143) #Corresponding SEs
#coef.pov <- c(0.059, 0.066, -0.2085, -0.0313, 0.144, 0.115, -0.192, -0.103, -0.039, 0.080, -0.069) #Difference across group from group*pov frame
#se.pov <- c(0.130, 0.198, 0.1329, 0.1875, 0.137, 0.133, 0.097, 0.134, 0.125, 0.177, 0.142)

#Labels groups

groups <- c("Left ideology \n (N = 197, 137)", "Union member \n (N = 53, 281)", "Peronist \n (N = 159, 149)", "Clientelism \n (N = 57, 212)", "Low-income insider \n (N = 134, 160)", "Low-income worker \n (N = 143, 191)", "Low-skill worker \n (N = 222, 112)", "Older worker \n (N = 163, 171)", "Female \n (N = 141, 193)", "Knowledgeable \n (N = 265, 59)", "Low-skill insider \n (N = 194, 94)")

n <- length(groups)

#intersection of effects on y axis
yr <-  seq(0.9, n-0.1,1)
yp <-   seq(1.1, n+0.1,1)

t <- 1.96 #Critical t-value for 95% confidence interval

#Commenting out printing of PDF figure
pdf("Fig3.pdf")

#Parameters of plot region, to allow for wider left margin
par(mar=c(6.1,8.1,2.1,1.1))

#Call empty plot
plot(0,0,type="n",  ylim = c(0,n), xlim=c(-1, 1), 
     yaxt="n", xlab="", ylab="", main = , axes=F) #ylim=c(0,2),

#Add axes     
axis(1, cex.axis=1, tcl=-0.3)

axis(2, at=n:1, labels=groups, las=1, cex.axis=1, tick=F, line=-1.5, cex.lab=1.3)

mtext("Support for non-registered over registered workers", 1, line = 3, cex.lab=1.2)

abline(v=0, col="Black",lty=2, lwd=1)

#Add risk ATEs plus SEs (can do less than 95%)
points(coef.risk, yr, pch= 15, cex=1.1)
points(coef.pov, yp, pch= 17, cex=1.1)

segments(coef.risk -t*se.risk, yr, coef.risk + t*se.risk, yr, lwd=1.1)

segments(coef.pov - t*se.pov, yp, coef.pov + t*se.pov, yp, lwd=1.1)

#Grid lines
for(j in seq(1,n, 1)){
lines(c(-1, 1), c(j,j), col = "lightgray", lty = "dotted", lwd=0.9)
}
for(i in seq(-1, 1, 0.5)){
abline(v=i, col = "lightgray", lty = "dotted", lwd=0.9)
}

#Legend

legend(x=-0.95, y = 10, pch= c(15, 17), legend = c("Risk", "Poverty"))

dev.off()

